{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8c8b8008",
   "metadata": {},
   "source": [
    "## 元组（tuple）\n",
    "> 元组\n",
    "- 它是几乎和list完全一样的序列数据\n",
    "- 不同之处在于，元组一旦创建好就**不能改变** \n",
    "- 元组形式：用括号(1,2,3) \n",
    "- 元组方法: \n",
    "    - count() \n",
    "    - index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "74a95bdb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=11, tm_mday=11, tm_hour=21, tm_min=34, tm_sec=14, tm_wday=3, tm_yday=315, tm_isdst=0)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3fc43c0f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('apple', 'banana', 'apple')\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "fruits = \"apple\",\"banana\",\"apple\"\n",
    "print(fruits)\n",
    "print(type(fruits))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "aa44451c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fruits.count(\"apple\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "179a8ac2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fruits.index(\"banana\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "da676ddc",
   "metadata": {},
   "source": [
    "## 字典(dictionary)\n",
    "> 字典 \n",
    "- 字典的创建方式 \n",
    "    - 直接创建字典，按照字典的结构dict={key1:value1,key2:value2,...}\n",
    "    - dict()创建字典dict(key1=value1,key2=value2,...)\n",
    "    - 创建空字典，通过添加值的方法创建字典\n",
    "- 字典的一些性质"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4ee6b731",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'001': 'ahu', '002': 'peiqi', '003': 'qiaozhi'}\n",
      "{'name': 'ahu', 'sex': 'woman', 'age': 20, 'job': 'stdent'}\n"
     ]
    }
   ],
   "source": [
    "# 字典的创建\n",
    "# 第一种方法\n",
    "\n",
    "info = {\n",
    "    \"001\":\"ahu\",\n",
    "    \"002\":\"peiqi\",\n",
    "    \"003\":\"qiaozhi\"\n",
    "}\n",
    "info_ahu = {\n",
    "    \"name\":\"ahu\",\n",
    "    \"sex\":\"woman\",\n",
    "    \"age\": 20,\n",
    "    \"job\":\"stdent\"\n",
    "}\n",
    "print(info)\n",
    "print(info_ahu)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "46e203bf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'peiqi', 'sex': 'man', 'age': 21, 'job': '海王'}\n"
     ]
    }
   ],
   "source": [
    "# 第二种方法\n",
    "\n",
    "info_peiqi = dict(\n",
    "    name = \"peiqi\",\n",
    "    sex = \"man\",\n",
    "    age = 21,\n",
    "    job = \"海王\"\n",
    ")\n",
    "print(info_peiqi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9506b3ff",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'qiaozhi', 'sex': 'man', 'age': 25, 'job': 'student'}\n"
     ]
    }
   ],
   "source": [
    "# 第三种方法\n",
    "\n",
    "info_qiaozhi = {}\n",
    "\n",
    "info_qiaozhi[\"name\"] = \"qiaozhi\"\n",
    "info_qiaozhi[\"sex\"] = \"man\"\n",
    "info_qiaozhi[\"age\"] = 25\n",
    "info_qiaozhi[\"job\"] = \"student\"\n",
    "\n",
    "print(info_qiaozhi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd61dbb9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}